package team.zero.lemon.module.sys.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import team.zero.lemon.common.authz.annotation.AuthPassport;
import team.zero.lemon.common.persistence.Page;
import team.zero.lemon.common.security.session.SessionContext;
import team.zero.lemon.common.web.BaseController;
import team.zero.lemon.module.sys.entity.Portal;
import team.zero.lemon.module.sys.entity.PortalUser;
import team.zero.lemon.module.sys.service.PortalService;

import java.util.List;

/**
 * Created by bolin on 2016/11/10.
 */
@Controller
@ResponseBody
@AuthPassport
@RequestMapping(value = "${adminPath}/sys/portal", method = {RequestMethod.POST, RequestMethod.GET})
public class PortalController extends BaseController {
    @Autowired
    private PortalService portalService;

    @AuthPassport
    @RequestMapping("/query/all")
    public List<Portal> findAllPortal() {
        return portalService.findAll();
    }

    @AuthPassport
    @RequestMapping("/query/userId")
    public List<Portal> findPortalByUserId() {
        return portalService.findPortalByUserId(SessionContext.getSession().getId());
    }
    @AuthPassport
    @RequestMapping("/save")
    public int SavePortal(@RequestBody Portal portal) {
        return portalService.save(portal);
    }
    @AuthPassport
    @RequestMapping("/user/save")
    public int savePortalUser(@RequestBody List<PortalUser> portalUsers) {
        return portalService.savePortalUser(portalUsers);
    }
    @AuthPassport
    @RequestMapping("/query/page")
    public Page<Portal> findPortal(@RequestBody Portal portal) {
        return portalService.findPage(portal);
    }
    @AuthPassport
    @RequestMapping("/delete/ids")
    public int deletePortal(@RequestBody Portal portal) {
        return portalService.deleteLogicMulti(portal);
    }
}
